/**
 * Copyright (c) 2016-2019 人人开源 All rights reserved.
 * <p>
 * https://www.renren.io
 * <p>
 * 版权所有，侵权必究！
 */

package com.songlanyun.common.utils;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonValue;
import com.songlanyun.common.enums.OpusConstant;

/**
 * Redis所有Keys
 *
 * @author Mark sunlightcs@gmail.com
 */
public class RedisKeys {

    public static String getSysConfigKey(String key) {
        return "lida:sys:config:" + key;
    }

    /**
     * 登陆admin token
     **/
    public static String getTokenConfigKey(String key) {
        return "lida:admin:token:" + key;
    }

    /**
     * 登陆api token
     **/
    public static String getWxTokenConfigKey(String key) {
        return "lida:api:token:" + key;
    }

    /**
     * 用户对应的数据权限
     **/
    public static String getUserDataPrivKey(String key) {
        return "lida:data_priv:" + key;
    }

    /**
     * 限流
     **/
    public static String getLimitKey(String key) {
        return "lida:limit:" + key;
    }

    /**
     * 微信开放平台accessToken
     **/
    public static String getWxAppToken(String key) {
        return "wx:app:token" + key;
    }

    /**
     * 电话号码对应的验证码
     **/
    public final static String VERFITY_CODE = "lida:vercode:";

    /**
     * 快钱银行卡绑定验证信息
     */
    public final static String getKqBankBindCode(String key) {
        return "kq:bank:card:verify:bind" + key;
    }

    /**
     * 快钱银行卡支付验证信息
     */
    public final static String getKqBankPayCode(String key) {
        return "kq:bank:card:verify:pay" + key;
    }

    /**
     * 快钱银行卡支付验证信息
     */
    public final static String getKqBankPay(String key) {
        return "kq:bank:card:pay" + key;
    }

    /**
     * 积分价格
     */
    public final static String POINT_PRICE_KEY = "point:price";

    public static String getRecentlyWatched(String key) {
        return "studying:recently:watched:" + key;
    }

    /**
     * 个推客户端ID
     **/
    public static String getPushCid(String key) {
        return "push:cid:" + key;
    }

    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public static enum BbsKey {

        BROWSE_OPUS_KEY("browse:opus:key:"),//浏览作品数
        LIKE_OPUS_KEY("like:opus:key:"),//点赞作品数
        SHARE_OPUS_KEY("share:opus:key:"),//分享作品数
        COMMENT_OPUS_KEY("comment:opus:key:"),//评论作品数
        BROWSE_ARTICLE_KEY("browse:article:key:"),//浏览文章数
        LIKE_ARTICLE_KEY("like:article:key:"),//点赞文章数
        SHARE_ARTICLE_KEY("share:article:key:"),//分享文章数
        COMMENT_ARTICLE_KEY("comment:article:key:"),//评论文章数

        /**
         * * 0 opus 作品，
         * * 1 article 文章，
         * * 2 common_goods 普通商品
         * * 3 service_goods 服务商品
         * * 4 seckill_goods秒杀商品
         * * 5 group_buy_goods拼团商品
         */
        SHARE_COMMON_GOODS_KEY("share:common:goods:key:"),//分享普通商品
        SHARE_SERVICE_GOODS_KEY("share:service:goods:key:"),//分享服务商品
        SHARE_SECKILL_GOODS_KEY("share:seckill:goods:key:"),//分享秒杀商品
        SHARE_GROUP_BUY_GOODS_KEY("share:group:buy:goods:key:"),//分享拼团商品
        ;


        @EnumValue
        @JsonValue
        private String key;

        BbsKey(String key) {
            this.key = key;
        }

        public String getKey() {
            return this.key;
        }

        public static BbsKey getByCode(String key) {
            for (BbsKey bbsKey : values()) {
                if (bbsKey.getKey() == key) {
                    return bbsKey;
                }
            }
            return null;
        }
    }

    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public enum IncrementKey {

        INFORMATION_BROWSE_KEY("increment:information:browse:key:"),//资讯浏览key
        INFORMATION_SHARE_KEY("increment:information:share:key:"),//资讯分享key
        ;

        @EnumValue
        @JsonValue
        private String key;

        IncrementKey(String key) {
            this.key = key;
        }

        public String getKey(Long id) {
            if (ObjectUtil.isNull(id)) {
                return this.key + "*";
            } else {
                return this.key + id.toString();
            }
        }
    }

}
